/*
 * @Descripttion:
 * @Author: voanit
 * @Date: 2022-05-09 16:52:47
 * @LastEditors: voanit
 * @LastEditTime: 2022-05-09 16:57:37
 */
import { useState, useEffect } from 'react'
export function useMouse() {
  const [position, setPosition] = useState({
    x: 0,
    y: 0,
  })
  const fn = (e) => {
    setPosition(() => {
      return {
        x: e.clientX,
        y: e.clientY,
      }
    })
  }
  useEffect(() => {
    window.addEventListener('mousemove', fn)
    return () => {
      window.removeEventListener('mousemove', fn)
    }
  }, [])
  return position
}
